<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    $(function() {
        $('#bguserinfoEditForm').form({
            url : '${path}/bguserinfo/edit',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#bguserinfoEditForm');
                    parent.$.messager.alert('错误', eval(result.msg), 'error');
                }
            }
        });
    });
    //检查图片的格式是否正确,同时实现预览  
    function setImagePreview(obj, localImagId, imgObjPreview,maxwidth,maxheight) {  
        var array = new Array('gif', 'jpeg', 'png', 'jpg', 'bmp'); //可以上传的文件类型  
        if (obj.value == '') {  
            $.messager.alert("让选择要上传的图片!");  
            return false;  
        }  
        else {  
            var fileContentType = obj.value.match(/^(.*)(\.)(.{1,8})$/)[3]; //这个文件类型正则很有用   
            ////布尔型变量  
            var isExists = false;  
            //循环判断图片的格式是否正确  
            for (var i in array) {  
                if (fileContentType.toLowerCase() == array[i].toLowerCase()) {  
                    //图片格式正确之后，根据浏览器的不同设置图片的大小  
                    if (obj.files && obj.files[0]) {  
                        //火狐下，直接设img属性   
                        imgObjPreview.style.display = 'block';  
                        imgObjPreview.style.width = maxwidth;  
                        imgObjPreview.style.height = maxheight;  
                        //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式   
                        imgObjPreview.src = window.URL.createObjectURL(obj.files[0]);  
                    }  
                    else {  
                        //IE下，使用滤镜   
                        obj.select();  
                        var imgSrc = document.selection.createRange().text;  
                        //必须设置初始大小   
                        localImagId.style.width = maxheight;  
                        localImagId.style.height = maxheight;  
                        //图片异常的捕捉，防止用户修改后缀来伪造图片   
                        try {  
                            localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";  
                            localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;  
                        }
                        catch (e) {  
                            $.messager.alert("您上传的图片格式不正确，请重新选择!");  
                            return false;
                        }  
                        imgObjPreview.style.display = 'none';  
                        document.selection.empty();  
                    }  
                    isExists = true;  
                    return true;  
                }  
            }  
            if (isExists == false) {  
                $.messager.alert("上传图片类型不正确!");  
                return false;  
            }  
            return false;  
        }
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;padding: 3px;">
        <form id="bguserinfoEditForm" method="post" enctype="multipart/form-data">
        <input name="id" type="hidden"  value="${bguserinfo.id}">
             <table class="grid">
                <tr>
                    <td>预览图</td>
                    <td>
                    	<div id="localImag">
                    		<%--预览，默认图片--%>
						    <c:if test="${not empty bguserinfo.preview}">
								<img id="divimg" alt="预览图片"  src="${bguserinfo.preview}" style="width: 150px; height: 170px;"/>   
							</c:if>
							<c:if test="${empty bguserinfo.preview}">
								<img id="divimg" alt="预览图片"  src="/static/style/images/bg_head.png" style="width: 150px; height: 170px;"/>   
							</c:if>
						</div>  
                    	  选择图片:<input id="idFile" name="pic_manPhoto" onchange="javascript:setImagePreview(this,localImag,divimg,'150px','170px');" type="file" />
                    	 <input id="preview" name="preview"  type="hidden" value="${bguserinfo.preview}"/>
                    </td>
                </tr> 
                <tr>
                    <td>名称</td>
                    <td><input style="width:525px" name="name" type="text" class="easyui-validatebox" value="${bguserinfo.name}"></td>
                </tr> 
                <tr>
                    <td>音频</td>
                    <td><input style="width:525px" name="audio" type="text" class="easyui-validatebox span2" value="${bguserinfo.audio}"></td>
                </tr> 
                
                <tr>
                    <td>视频</td>
                    <td><input style="width:525px" name="video" type="text" class="easyui-validatebox span2" value="${bguserinfo.video}"></td>
                </tr> 
                <tr>
                    <td>标签</td>
                    <td><input style="width:525px" name="tags" type="text" class="easyui-validatebox span2" value="${bguserinfo.tags}"></td>
                </tr>
                 <tr>
                    <td>详情</td>
                    <td>
                    	<textarea rows="10" cols="80" name="detail" >${bguserinfo.detail}</textarea>
                    </td>
                </tr> 
            </table>
        </form>
    </div>
</div>